package testSudoku;
 
import static org.junit.Assert.*;

import org.junit.Test;
import sudoku.*;
import junit.framework.TestCase;

public class testGet_hints {
	//Difficulty is hard and answering question 2
	private Manager m  = new Manager(3,1);
	
	private void Check_RemainHints()
	{
		if(m.hint_ava())
			   m.get_hint();
	}
	
	@Test 
	//Get hints function will skip one cell if it may cause repeat number in row
	public void testRowRepeat()
	{
		Board b = m.getboard();
		m.set_board(0,0,'6');
		m.set_board(2,0,'2');
		m.set_board(3,0,'4');
		m.set_board(5,0,'9');
		Check_RemainHints();
		
		char [][]result = new char[][] {
		{'6','5','2','4','7','9',' ','1','8'},
		{'7',' ',' ','2',' ',' ','4',' ','5'},
		{' ','4',' ',' ','8',' ','7',' ',' '},
		{'2',' ',' ','1',' ','4',' ',' ',' '},
		{'1',' ',' ','7',' ','8',' ',' ','9'},
		{' ',' ',' ','3',' ','6',' ',' ','7'},
		{' ',' ','6',' ','3',' ',' ','9',' '},
		{'5',' ','4',' ',' ','7',' ',' ','1'},
		{' ','1',' ',' ','4',' ',' ','7',' '}};
		
		assertArrayEquals(result,b.getboard());
	}
	
	@Test
	//Get hints function will skip one cell if it may cause repeat number in column
	public void testColumnRepeat()
	{
		Board b = m.getboard();
		m.set_board(0,0,'6');
		m.set_board(2,0,'3');
		m.set_board(3,0,'4');
		m.set_board(5,0,'9');
		m.set_board(6,0,'2');
		m.set_board(8,0,'8');
		m.set_board(1,1,'8');
		Check_RemainHints();
	
		char [][]result = new char[][] {
		{'6','5','3','4','7','9','2','1','8'},
		{'7','8',' ','2','1',' ','4',' ','5'},
		{' ','4',' ',' ','8',' ','7',' ',' '},
		{'2',' ',' ','1',' ','4',' ',' ',' '},
		{'1',' ',' ','7',' ','8',' ',' ','9'},
		{' ',' ',' ','3',' ','6',' ',' ','7'},
		{' ',' ','6',' ','3',' ',' ','9',' '},
		{'5',' ','4',' ',' ','7',' ',' ','1'},
		{' ','1',' ',' ','4',' ',' ','7',' '}};
		
		assertArrayEquals(result,b.getboard());
	}
		
	@Test 
	//Get hints function will skip one cell if it may cause repeat number in the 3*3 region
	public void testRegionRepeat()
	{
		Board b = m.getboard();
		m.set_board(0,0,'8');
		m.set_board(2,0,'2');
		m.set_board(3,0,'4');
		m.set_board(5,0,'3');
		m.set_board(6,0,'9');
		m.set_board(8,0,'8');
		Check_RemainHints();
		
		char [][]result = new char[][] {
		{'8','5','2','4','7','3','9','1','8'},
		{'7',' ','3','2',' ',' ','4',' ','5'},
		{' ','4',' ',' ','8',' ','7',' ',' '},
		{'2',' ',' ','1',' ','4',' ',' ',' '},
		{'1',' ',' ','7',' ','8',' ',' ','9'},
		{' ',' ',' ','3',' ','6',' ',' ','7'},
		{' ',' ','6',' ','3',' ',' ','9',' '},
		{'5',' ','4',' ',' ','7',' ',' ','1'},
		{' ','1',' ',' ','4',' ',' ','7',' '}};
		
		assertArrayEquals(result,b.getboard());
	}
	
	//Normal get hints function
	@Test
	public void NormalGethints()
	{
		Board b = m.getboard();
		Check_RemainHints();
		
		char [][]result = new char[][] {
		{'6','5',' ',' ','7',' ',' ','1',' '},
		{'7',' ',' ','2',' ',' ','4',' ','5'},
		{' ','4',' ',' ','8',' ','7',' ',' '},
		{'2',' ',' ','1',' ','4',' ',' ',' '},
		{'1',' ',' ','7',' ','8',' ',' ','9'},
		{' ',' ',' ','3',' ','6',' ',' ','7'},
		{' ',' ','6',' ','3',' ',' ','9',' '},
		{'5',' ','4',' ',' ','7',' ',' ','1'},
		{' ','1',' ',' ','4',' ',' ','7',' '}};
		
		assertArrayEquals(result,b.getboard());
	}
	@Test
	//Even user input get hint function more than 3 times. System will only allow three hints.
	public void OnlyThreehints()
	{
		Board b = m.getboard();
		Check_RemainHints();
		Check_RemainHints();
		Check_RemainHints();
		Check_RemainHints();
		
		char [][]result = new char[][] {
		{'6','5','2','4','7',' ',' ','1',' '},
		{'7',' ',' ','2',' ',' ','4',' ','5'},
		{' ','4',' ',' ','8',' ','7',' ',' '},
		{'2',' ',' ','1',' ','4',' ',' ',' '},
		{'1',' ',' ','7',' ','8',' ',' ','9'},
		{' ',' ',' ','3',' ','6',' ',' ','7'},
		{' ',' ','6',' ','3',' ',' ','9',' '},
		{'5',' ','4',' ',' ','7',' ',' ','1'},
		{' ','1',' ',' ','4',' ',' ','7',' '}};
				
		assertArrayEquals(result,b.getboard());
	}
	
	
}
